/** 
 ** Copyright (c) 2010 Ushahidi Inc
 ** All rights reserved
 ** Contact: team@ushahidi.com
 ** Website: http://www.ushahidi.com
 ** 
 ** GNU Lesser General Public License Usage
 ** This file may be used under the terms of the GNU Lesser
 ** General Public License version 3 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.LGPL included in the
 ** packaging of this file. Please review the following information to
 ** ensure the GNU Lesser General Public License version 3 requirements
 ** will be met: http://www.gnu.org/licenses/lgpl.html.	
 **	
 **
 ** If you have questions regarding the use of this file, please contact
 ** Ushahidi developers at team@ushahidi.com.
 ** 
 **/

package com.ushahidi.android.app;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;

public class UshahidiSplashScreen extends Activity
{
    private boolean active     = true;

    private int     splashTime = 3000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
	super.onCreate(savedInstanceState);
	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.splash_screen);

	// thread for displaying the SplashScreen
	Thread splashTread = new Thread()
	{
	    @Override
	    public void run()
	    {
		try
		{
		    int waited = 0;
		    while (active && (waited < splashTime))
		    {
			sleep(100);
			if (active)
			{
			    waited += 100;
			}
		    }
		}
		catch (InterruptedException e)
		{
		    // do nothing
		}
		finally
		{
		    startActivity(new Intent(UshahidiSplashScreen.this,
			    Ushahidi.class));
		    finish();
		}
	    }
	};
	splashTread.start();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
	if (event.getAction() == MotionEvent.ACTION_DOWN)
	{
	    active = false;
	}
	return true;
    }

}
